package com.ruoyi.business.controller;

import com.ruoyi.business.domain.BusCar;
import com.ruoyi.business.dto.CarDto;
import com.ruoyi.business.service.IBusCarService;
import com.ruoyi.business.service.IBusCustomerService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
import java.util.List;

/**
 * 内容:
 * 作者: cy
 */
@RestController
@Api(tags = "车辆管理接口")
@RequestMapping("business/car")
public class CarController extends BaseController {

   @Autowired
   private IBusCarService busCarService;

   @GetMapping("list")
   @ApiOperation("分页查询车辆信息")
   public TableDataInfo getCarPage(CarDto carDto){
      startPage();
      LoginUser loginUser = getLoginUser();
       List<BusCar> busCarList = busCarService.getCarPage(carDto,loginUser);
      return getDataTable(busCarList);
   }
   @PostMapping
   @ApiOperation("新增车辆")
   public AjaxResult addCar(@RequestBody CarDto carDto){
      LoginUser loginUser = getLoginUser();
      return toAjax(busCarService.addCar(carDto,loginUser));
   }
   @GetMapping("{id}")
   @ApiOperation("根据id查询车辆信息")
   public AjaxResult getCarInfo(@PathVariable("id")Long id){
      CarDto carDto = busCarService.getCarInfo(id);
      return AjaxResult.success(carDto);
   }
   @PutMapping
   @ApiOperation("修改车辆信息")
   public AjaxResult updateCar(@RequestBody CarDto carDto){
      LoginUser loginUser = getLoginUser();
      return toAjax(busCarService.updateCar(carDto,loginUser));

   }
   @DeleteMapping("{ids}")
   @ApiOperation("根据车辆ids删除车辆")
   public AjaxResult delCar(@PathVariable("ids")List<Long> ids){
      LoginUser loginUser = getLoginUser();
      return toAjax(busCarService.delCar(ids,loginUser));
   }

}
